package com.seezoon.infrastructure.configuration;

import com.seezoon.infrastructure.configuration.interceptor.SessionInterceptor;
import com.seezoon.infrastructure.configuration.interceptor.ThreadIdMdcInterceptor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * spring mvc 配置
 *
 * @author huangdengfeng
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
public class AutoWebMvcConfigurer implements WebMvcConfigurer {

    private static final String ALL = "/**";
    private static final String[] PUBLIC = {"/swagger-ui/**", "/v3/api-docs/**",
            "/**/*.html"};

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ThreadIdMdcInterceptor()).addPathPatterns(ALL);
        registry.addInterceptor(new SessionInterceptor()).addPathPatterns(ALL).excludePathPatterns(PUBLIC);
    }
}
